﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace lcmyjobs.DAL
{
	/// <summary>
	/// 数据访问类:enterprise_basicf
	/// </summary>
	public partial class enterprise_basicf
	{
		public enterprise_basicf()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("enterprise_bfid", "enterprise_basicf"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int enterprise_bfid)
		{
			int rowsAffected;
			SqlParameter[] parameters = {
					new SqlParameter("@enterprise_bfid", SqlDbType.Int,4)};
			parameters[0].Value = enterprise_bfid;

			int result= DbHelperSQL.RunProcedure("enterprise_basicf_Exists",parameters,out rowsAffected);
			if(result==1)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		///  增加一条数据
		/// </summary>
		public bool Add(lcmyjobs.Model.enterprise_basicf model)
		{
			int rowsAffected;
			SqlParameter[] parameters = {
					new SqlParameter("@enterprise_bfid", SqlDbType.Int,4),
					new SqlParameter("@enterprise_bid", SqlDbType.Int,4),
					new SqlParameter("@trades_id", SqlDbType.Int,4)};
			parameters[0].Value = model.enterprise_bfid;
			parameters[1].Value = model.enterprise_bid;
			parameters[2].Value = model.trades_id;

			DbHelperSQL.RunProcedure("enterprise_basicf_ADD",parameters,out rowsAffected);
            if (rowsAffected == 1)
                return true;
            else
                return false;
        }

		/// <summary>
		///  更新一条数据
		/// </summary>
		public bool Update(lcmyjobs.Model.enterprise_basicf model)
		{
			int rowsAffected=0;
			SqlParameter[] parameters = {
					new SqlParameter("@enterprise_bfid", SqlDbType.Int,4),
					new SqlParameter("@enterprise_bid", SqlDbType.Int,4),
					new SqlParameter("@trades_id", SqlDbType.Int,4)};
			parameters[0].Value = model.enterprise_bfid;
			parameters[1].Value = model.enterprise_bid;
			parameters[2].Value = model.trades_id;

			DbHelperSQL.RunProcedure("enterprise_basicf_Update",parameters,out rowsAffected);
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int enterprise_bfid)
		{
			int rowsAffected=0;
			SqlParameter[] parameters = {
					new SqlParameter("@enterprise_bfid", SqlDbType.Int,4)};
			parameters[0].Value = enterprise_bfid;

			DbHelperSQL.RunProcedure("enterprise_basicf_Delete",parameters,out rowsAffected);
			if (rowsAffected > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string enterprise_bfidlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from enterprise_basicf ");
			strSql.Append(" where enterprise_bfid in ("+enterprise_bfidlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public lcmyjobs.Model.enterprise_basicf GetModel(int enterprise_bfid)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@enterprise_bfid", SqlDbType.Int,4)};
			parameters[0].Value = enterprise_bfid;

			lcmyjobs.Model.enterprise_basicf model=new lcmyjobs.Model.enterprise_basicf();
			DataSet ds= DbHelperSQL.RunProcedure("enterprise_basicf_GetModel",parameters,"ds");
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["enterprise_bfid"]!=null && ds.Tables[0].Rows[0]["enterprise_bfid"].ToString()!="")
				{
					model.enterprise_bfid=int.Parse(ds.Tables[0].Rows[0]["enterprise_bfid"].ToString());
				}
				if(ds.Tables[0].Rows[0]["enterprise_bid"]!=null && ds.Tables[0].Rows[0]["enterprise_bid"].ToString()!="")
				{
					model.enterprise_bid=int.Parse(ds.Tables[0].Rows[0]["enterprise_bid"].ToString());
				}
				if(ds.Tables[0].Rows[0]["trades_id"]!=null && ds.Tables[0].Rows[0]["trades_id"].ToString()!="")
				{
					model.trades_id=int.Parse(ds.Tables[0].Rows[0]["trades_id"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select enterprise_bfid,enterprise_bid,trades_id ");
			strSql.Append(" FROM enterprise_basicf ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" enterprise_bfid,enterprise_bid,trades_id ");
			strSql.Append(" FROM enterprise_basicf ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "enterprise_basicf";
			parameters[1].Value = "enterprise_bfid";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

